﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Configuration;

namespace DIProject.Stock
{	public partial class WriteOffRpt : Form
	{	private int docId;
		private string textFormat;

		public WriteOffRpt() : this(0)
		{
		}
		public WriteOffRpt(int docId)
		{	InitializeComponent();
			this.docId = docId;
			textFormat = Text;
		}

		private DIProject.DataSets.Reports reports = new DIProject.DataSets.Reports();
		private DIProject.DataSets.ReportsTableAdapters.WriteOff_InfoTableAdapter infoTableAdapter = new DIProject.DataSets.ReportsTableAdapters.WriteOff_InfoTableAdapter();
		private DIProject.DataSets.ReportsTableAdapters.WriteOff_DataTableAdapter dataTableAdapter = new DIProject.DataSets.ReportsTableAdapters.WriteOff_DataTableAdapter();

		private void WriteOffRpt_Load(object sender, EventArgs e)
		{	try
			{	WriteOff.FileName = Path.Combine(ConfigurationManager.AppSettings["ReportsPath"], "Stock/WriteOff.rpt");
				WriteOff.Load();
			}
			catch(Exception ex)
			{	MessageBox.Show(this, ex.Message, Properties.Resources.strError, MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}

		private void WriteOff_InitReport(object sender, EventArgs e)
		{	WriteOff.SetDataSource(reports);
		}

		private void WriteOff_RefreshReport(object sender, EventArgs e)
		{	infoTableAdapter.Fill(reports.WriteOff_Info, docId);
			dataTableAdapter.Fill(reports.WriteOff_Data, docId);
			if(reports.WriteOff_Info.Count > 0)
			{	DIProject.DataSets.Reports.WriteOff_InfoRow info = reports.WriteOff_Info[0];
				Text = string.Format(textFormat, info.DocNumber, info.DocDate);
			}
		}
	}
}